#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int MAXN=1e5+10;
char a[MAXN],s[MAXN*2];
int sa[MAXN*2],rk[MAXN*2],height[MAXN*2],_max,len,n;
struct temp
{
	int x,y,num;
	bool operator<(const temp b)const
	{
		return x==b.x?y<b.y:x<b.x;
	}
}tmp[MAXN*2];
void cal_rk()
{
	for(int i=0;(1<<i)<=n;++i)
	{
		memset(tmp,0,sizeof(tmp));
		for(int j=1;j<=n;++j)
		{
			tmp[j].num=j;
			tmp[j].x=rk[j];
			if(j+(1<<i)<=n)tmp[j].y=rk[j+(1<<i)];
		}
		sort(tmp+1,tmp+1+n);
		int cnt=0;
		for(int j=1;j<=n;++j)
		{
			if(tmp[j].x!=tmp[j-1].x||tmp[j].y!=tmp[j-1].y)++cnt;
			rk[tmp[j].num]=cnt;
		}
	}
	return;
}
void cal_sa()
{
	for(int i=1;i<=n;++i)
		sa[rk[i]]=i;
	return;
}
void cal_height()
{
	int j,k=0;
	for(int i=1;i<=n;++i)
	{
		if(k)--k;
		j=sa[rk[i]-1];
		while(s[i+k]==s[j+k])++k;
		height[rk[i]]=k;
	}
	return;
}
int main()
{
	scanf("%s",a+1);
	strcpy(s+1,a+1);
	len=strlen(s+1);
	scanf("%s",a+1);
	s[len+1]='a'-1;
	strcpy(s+len+2,a+1);
	n=strlen(s+1);
	for(int i=1;i<=n;++i)rk[i]=s[i]-'a'+1;
	cal_rk();
	cal_sa();
	cal_height();
	for(int i=3;i<=n;++i)
	{
		if(sa[i-1]>0&&sa[i-1]<=len&&sa[i]>len)_max=max(_max,height[i]);
		if(sa[i]>0&&sa[i]<=len&&sa[i-1]>len)_max=max(_max,height[i]);
	}
	printf("%d\n",_max);
	return 0;
}
